<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>

<div class="app">
    <section class="layout">
        <section class="main-content col-lg-12" id="drugBuyPlanCreateDiv">
            <div class="content-wrap">
                <div class="wrapper" style="bottom: 50px;">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#" onclick="loadDiv('mainCenterDiv','${ctx}/drug/buyPlanAudit/createPlanIndex')">采购计划生成</a>
                        </li>
                    </ul>
                    <section class="panel panel-default">
                        <div class="panel-body">
                            <div class="table-responsive no-border">
                                <div class="datatable-top">
                                    <div class="pull-left">
                                        <%--<form:form id="searchForm" modelAttribute="drugBuyPlan" method="post" class="form-inline">--%>
                                            <div class="form-group">
                                                <input id="getBtn" class="btn btn-info" type="button" onclick="getBtn()" value="生成" />
                                                <input id="addBtn" class="btn btn-info" type="button" onclick="addBuyPlanItem()" value="增加" />
                                                <input id="btnSubmit" class="btn btn-primary" type="button" onclick="saveBuyPlan()" value="保存" />
                                            </div>
                                        <%--</form:form>--%>
                                    </div>
                                </div>
                                <%--<form id="saveBuyPlan" modelAttribute="drugBuyPlan" onsubmit="return formSaveLoad('mainCenterDiv','saveBuyPlan','${ctx}/drug/buyPlanAudit/saveDrugBuyPlanCreate','${ctx}/drug/buyPlanAudit/createPlanIndex');"--%>
                                      <%--method="post" class="form-horizontal">--%>
                                <form id="saveBuyPlan" action="${ctx}/drug/buyPlanAudit/saveDrugBuyPlanCreate" method="post" class="form-inline">
                                <table id="contentTable" class="table table-bordered table-striped mg-t datatable">
                                    <thead>
                                    <tr>
                                        <th hidden>jsonText</th>
                                        <th hidden>infoId</th>
                                        <th>采购序号</th>
                                        <th>药品编码</th>
                                        <th>药品名称</th>
                                        <th>包装数量</th>
                                        <th>包装规格</th>
                                        <th hidden>包装单位代码</th>
                                        <th>包装单位</th>
                                        <th>最小规格</th>
                                        <th hidden>最小单位代码</th>
                                        <th>最小单位</th>
                                        <th hidden>剂型代码</th>
                                        <th>剂型</th>
                                        <th hidden>厂家ID</th>
                                        <th>厂家</th>
                                        <th>批价</th>
                                        <th>售价</th>
                                        <th>计划数量</th>
                                        <th>计划金额</th>
                                        <th>库存参考数</th>
                                        <%--<th>月消耗量</th>--%>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                </table>
                                </form>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </section>
        <%--右侧药品明细信息--%>
        <section class="main-content col-lg-4" style="display: none" id="drugPlanRightDiv">
            <div class="content-wrap" id="rigthCenterDiv">
            </div>
        </section>
    </section>
</div>
<script type="text/javascript">
    //弹出右边增加采购药品明细框
    function addBuyPlanItem() {
        $("#drugBuyPlanCreateDiv").attr("class", "main-content col-lg-8");
        $("#drugPlanRightDiv").show('normal');
        return loadDiv('rigthCenterDiv', '${ctx}/drug/buyPlanAudit/createPlanForm');
    }

    function removeList(btn) {
        $(btn).parent().parent().remove();
    }

    //保存
    function saveBuyPlan() {
        $("#saveBuyPlan").ajaxSubmit({
            success: function (data) {
                if (data.code == 'success') {
                    toastr.success(data.data);
                    loadDiv('drugBuyPlanCreateDiv','${ctx}/drug/buyPlanAudit/createPlanIndex');
                } else {
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                toastr.error(data.data);
            }
        });
    }

    //根据输入的计划数量计算计划金额
    function changeFun(inputId, idx) {
        if (inputId == 'plannedSelling') {  //改变计划数量
            var num = $.trim($("#" + inputId + idx).val());
            var price = $.trim($("#tradePrice" + idx).val());
            $("#plannedAmount" + idx).val(Number(num) * Number(price));
        }
    }
</script>